<include file="Admin@Public/header" /> 

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <ol class="breadcrumb">
      <li>网站内容</li>
      <li>栏目管理</li>
      <li class="active">编辑</li>
    </ol>
     
    <form  class="form-horizontal" role="form" action="__URL__/save" >
      <input type="hidden" name="inputId" value="{$type.id}" > 

      <div class="form-group">
        <label for="inputParent" class="col-sm-2 control-label">父级 </label>
        <div class="col-sm-4">
          <?php $allTypes = R('Content/Type/tree'); ?>
          <select name="inputParent" class="form-control" id="inputParent">
            <option value="0">作为父级</option>
            <volist name="allTypes" id="allType">
              <option value="{$allType.id}" <if condition="$allType['id'] == $type['parentid']">selected="selected"</if> >{$allType.html}{$allType.name}</option>
            </volist>  
          </select>
        </div>
      </div>
      <div class="form-group">
        <label for="inputName" class="col-sm-2 control-label">栏目 </label>
        <div class="col-sm-4">
          <input type="text" class="form-control" id="inputName" name="inputName" placeholder="请输入栏目分类名" datatype="*2-10" errormsg="<i class='icon-warning-sign'></i> 栏目分类名名在2~10位之间"  nullmsg="<i class='icon-warning-sign'></i> 请填写信息！" value="{$type.name}" >
        </div>
        <div class="Validform_checktip">
           <div class="Validform-info">栏目分类名至少2个字符,最多10个字符<span class="dec"><s class="dec1">&#9670;</s><s class="dec2">&#9670;</s></span></div>
        </div>
      </div>
      <div class="form-group">
        <label for="inputUrl" class="col-sm-2 control-label">URL </label>
        <div class="col-sm-4">
          <input type="text" class="form-control" id="inputUrl" name="inputUrl" placeholder="请输入栏目自定义链接" datatype="p_url" errormsg="<i class='icon-warning-sign'></i> 链接含有非法字符或已存在" sucmsg="<i class='icon-ok'></i>"  ignore="ignore" ajaxurl="/Plugin/verify/validNoUrl2?m=type&oid={$type.id}" value="{$article.url}">
        </div>
        <div class="Validform_checktip">
           <div class="Validform-info">自定义链接如：新闻 news <span class="dec"><s class="dec1">&#9670;</s><s class="dec2">&#9670;</s></span></div>
        </div>
      </div>
        <?php $tpl_list = getTplFiles('List'); ?>
      <div class="form-group">
        <label for="inputTemplatelist" class="col-sm-2 control-label">列表模版</label>
        <div class="col-sm-4">
          <select name="inputTemplatelist" id="inputTemplatelist" class="form-control">
            <volist name="tpl_list" id="tpl">
              <option value="{$tpl.name}" <if condition="$type['templatelist'] == $tpl['name']">selected="selected"</if>>{$tpl.fullname}</option>
            </volist>  
          </select>
        </div>
      </div>
      <?php $tpl_list = getTplFiles('Article'); ?>
      <div class="form-group">
        <label for="inputTemplate"  class="col-sm-2 control-label">单页模版</label>
        <div class="col-sm-4">
          <select name="inputTemplate" id="inputTemplate" class="form-control">
            <volist name="tpl_list" id="tpl">
              <option value="{$tpl.name}"  <if condition="$type['template'] == $tpl['name']">selected="selected"</if> >{$tpl.fullname}</option>
            </volist>  
          </select>
        </div>
      </div>
      <?php $redirect = unserialize($type["redirect"]); $rtype=$redirect['rtype']; $rid=$redirect['rid'];?>
      <div class="form-group">
        <label for="inputRedirectType"  class="col-sm-2 control-label">链接定向</label>
        <div class="col-sm-2">
          <select name="inputRedirectType" id="inputRedirectType" class="form-control" onchange="changRedirectType(this.value)">
              <option value="type"  <if condition="$rtype == 'type' ">selected="selected"</if> >分类</option>
              <option value="list"  <if condition="$rtype == 'list' ">selected="selected"</if> >列表</option>
              <option value="article"  <if condition="$rtype == 'article' ">selected="selected"</if> >文章</option>
              <option value="page"  <if condition="$rtype == 'page' ">selected="selected"</if> >页面</option>
          </select>
        </div>
        <?php  
            $rList = R("Content/obj/getChildTypeByParentId",array($type['id']));
            $rArticle = R("Content/obj/getArticleByTypeId",array($type['id']));
            $rPage = getTplFiles('Page'); 
        ?>
        <div class="col-sm-2">
         <input type="hidden" name="inputRedirectId" id="inputRedirectId" value="{$rid}" > 

          <select id="rTypeShow" onchange="changRedirectId(this.value)" <if condition="$rtype eq 'type'">class="form-control"<else/>class="form-control hidden"</if>  >
            <volist name="rList" id="r">
              <option value="{$r.id}"  <if condition="$r['id'] == $rid">selected="selected"</if> >{$r.name}</option>
            </volist>  
          </select>
          <select id="rListShow" onchange="changRedirectId(this.value)" <if condition="$rtype eq 'list'">class="form-control"<else/>class="form-control hidden"</if> >
            <volist name="rList" id="r">
              <option value="{$r.id}"  <if condition="$r['id'] == $rid">selected="selected"</if> >{$r.name}</option>
            </volist>  
          </select>
          <select id="rArticleShow" onchange="changRedirectId(this.value)" <if condition="$rtype eq 'article'">class="form-control"<else/>class="form-control hidden"</if>>
            <volist name="rArticle" id="r">
              <option value="{$r.id}"  <if condition="$r['id'] == $rid">selected="selected"</if> >{$r.title}</option>
            </volist>  
          </select>
          <select id="rPageShow" onchange="changRedirectId(this.value)" <if condition="$rtype eq 'page'">class="form-control"<else/>class="form-control hidden"</if>>
            <volist name="rPage" id="r">
              <option value="{$r.name}"  <if condition="$r['name'] == $rid">selected="selected"</if> >{$r.fullname}</option>
            </volist>  
          </select>
        </div>
      </div>
      <div class="form-group">
        <label  class="col-sm-2 control-label"> </label>
        <div class="col-sm-4">
          <input type="button" class="btn btn-primary" value="编辑" id="btn_sub"/>
           <a href="__URL__/index" class="btn btn-default" >返回</a>
      </div>
    </div>
    </form> 
            
            
</div>
<script type="text/javascript">
  function changRedirectType(rtype){
      var redirectId;
      switch (rtype) {
        case 'type':
          $('#rTypeShow').removeClass("hidden");
          $('#rListShow').addClass("hidden");
          $('#rArticleShow').addClass("hidden");
          $('#rPageShow').addClass("hidden");
          redirectId=$('#rTypeShow').val();
          break ;
        case 'list':
          $('#rListShow').removeClass("hidden");
          $('#rTypeShow').addClass("hidden");
          $('#rArticleShow').addClass("hidden");
          $('#rPageShow').addClass("hidden");
          redirectId=$('#rListShow').val();
          break ;
        case 'article':
          $('#rArticleShow').removeClass("hidden");
          $('#rListShow').addClass("hidden");
          $('#rTypeShow').addClass("hidden");
          $('#rPageShow').addClass("hidden");
          redirectId=$('#rArticleShow').val();
          break;
        case 'page':
          $('#rPageShow').removeClass("hidden");
          $('#rArticleShow').addClass("hidden");
          $('#rListShow').addClass("hidden");
          $('#rTypeShow').addClass("hidden");
          redirectId=$('#rPageShow').val();
          break;
        default:
          break;
      }
      $('#inputRedirectId').val(redirectId);
  }
  function changRedirectId(rid){
     $('#inputRedirectId').val(rid);
  }

</script>

<include file="Admin@Public/script_form" /> 
<include file="Admin@Public/footer" /> 